package com.zgqb.loan.list.service;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.TbkItemGetRequest;
import com.taobao.api.response.TbkItemGetResponse;
import com.zgqb.loan.list.model.JSONData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service
public class TbkService {

    /**
     * 淘宝客商品查询
     *
     * @return
     */
    public JSONData taoBaotbkItemGet(){
        JSONData jsonData = new JSONData();
        TbkItemGetRequest req = new TbkItemGetRequest();
        TaobaoClient client = new DefaultTaobaoClient("url", "", "");
        req.setFields("num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick");
        req.setQ("女装");
        req.setCat("16,18");
        req.setItemloc("杭州");
        req.setSort("tk_rate_des");
        req.setIsTmall(false);
        req.setIsOverseas(false);
        req.setStartPrice(10L);
        req.setEndPrice(10L);
        req.setStartTkRate(123L);
        req.setEndTkRate(123L);
        req.setPlatform(1L);
        req.setPageNo(123L);
        req.setPageSize(20L);
        TbkItemGetResponse rsp = null;
        try {
            rsp = client.execute(req);
        } catch (ApiException e) {
            e.printStackTrace();
        }
        System.out.println(rsp.getResults());
        Map<String,Object> map = new HashMap<>();
        map.put("req",req);
        jsonData.setBody(map);
        return jsonData;
    }

}
